window.onload=function(){
    // 跳转到首页
    var all_main=document.querySelector(".nav-top-box-1").children[0]
    all_main.addEventListener("click", function () {
        window.location.href="/";
    });
    // 跳转到登录页面或者个人中心
    var nav_top_box_2=document.querySelector(".nav-top-box-2").children[0];
    var text_1=nav_top_box_2.innerHTML;
    console.log(text_1)
    nav_top_box_2.addEventListener("click",function() {
        if (text_1 == "登录") {
            window.location.href = "/User/login";
        } else {
            window.location.href = "/User/userInterface";
        }
    })
    // 点击退出跳转到主页
    var exit = document.querySelector(".exit")
    exit.addEventListener("click",function(){
        $.ajax({
            type: "post",
            url: "/User/loginOut",
            // data: {
            // },
            success: function (data) {
                // alert("退出")
                window.location.href="/";

            },error: function () {
                console.log("調取接口失敗")
            }
        })
    });
    // 跳转到购物车
    var shoppingcar=document.querySelector(".shoppingcar");
    shoppingcar.addEventListener("click",function () {
        window.location.href = "/User/myCarPage";
    })
    // 跳转到我的喜欢
    var mylike=document.querySelector(".mylike");
    mylike.addEventListener("click",function(){
        window.location.href = "/User/myLike";
    })
     // 点击首页跳转用户界面
     var fristPage=document.querySelector(".header-box-1").children[0];
     fristPage.addEventListener("click",function(){
         window.location.href="/User/userInterface"
     });
    // 点击收货地址跳转
    var address=document.querySelector(".user-news-box-1-1");
    address.addEventListener("click",function(){
        window.location.href="/addressPage";
    });
    // 账户设置隐藏显示
    var header_hidden=document.querySelector(".header-hidden");
    var number_fit=document.querySelector(".header-box-1").children[1];
    var q=document;
    console.log(header_hidden);
    number_fit.addEventListener("mouseover",function(){
        header_hidden.style.display="block";
    });
     q.addEventListener("click",function(){
         header_hidden.style.display="none";
    });
    header_hidden.addEventListener("click",function(ie){
        e.stopPropagation();
    })

    var nav_top=document.querySelectorAll(".main-right-top-nav");    
    console.log(nav_top);
    nav_top[0].addEventListener("click",function(){
        window.location.href="/User/allGoods";
    });
    nav_top[1].addEventListener("click",function(){
        window.location.href="/User/waitPay";
    });
    nav_top[2].addEventListener("click",function(){
        window.location.href="/User/sendGoods";
    });
    nav_top[4].addEventListener("click",function(){
        window.location.href="/User/waitAssess";
    });
    var id=document.querySelector(".id");
    console.log(id.innerHTML)
    // 点击跳转修改密码
    var change=document.querySelector(".changepassword");
    change.onclick=function () {
        window.location.href = "/User/updatePassword"
    }
    // 查询所有订单(已支付)
    var tb = document.querySelector("tbody");
    function fenYe1(x) {
        tb.innerHTML = "";
        $.ajax({
            type: "post",
            url: "/Order/queryAllOrderY",
            data: {
                userId: x
            },
            success: function (page) {
                for (let i = 0; i < page.length; i++) {
                    var x="";
                    var goodsName;
                    if(page[i].goodsName.length>20){
                        for (var j=0;j<=20;j++) {
                            x = x + page[i].goodsName[j];
                            goodsName=x+"...";
                        }
                    }else{
                        x=page[i].goodsName;
                        goodsName=x;
                    }
                    let list=`<tr class="tr1">
                                    <td>订单号:${page[i].orderNo}</td>
                                    <td><div class='delete-only-2'><i class='fa fa-trash' aria-hidden='true'></i></div></td>
                            </tr>
                            <tr class="tr2">
                                    <td>${goodsName}</td>
                                    <td>${page[i].allPrice}</td>
                                    <td>${page[i].goodsCount}</td>
                                    <td>${page[i].goodsPrice}</td>
                                    <td>支付成功</td>
                                    <td><p>追加评论</p><p>再次购买</p></td>
                            </tr>`
                    tb.insertAdjacentHTML("beforeend",list);
                }
                // 删除单个订单(已支付)
                var delete_only2=document.querySelectorAll(".delete-only-2");
                for (let i = 0; i <delete_only2.length; i++) {
                    delete_only2[i].addEventListener("click", function () {
                        console.log(111)
                        if (confirm("你确定要删除此点单吗?")) {
                            delete_only_2(page[i].goodsId, page[i].orderNo, id.innerHTML)
                            fenYe1(id.innerHTML);
                        }
                    })
                }

            }
        })
    }
    fenYe1(id.innerHTML);

    // 删除单个(已支付)
    function delete_only_2(x,y,z) {
        $.ajax({
            type: "post",
            url: "/Order/deleteOrderY",
            data: {
                goodsId:x,
                orderNo: y,
                userId: z
            },
            success: function (page) {
                alert("删除成功")
            }
        })
    }
}